using System.Collections.Generic;
using Belmost4PDA.Constants;
using Belmost4PDA.DatabaseWorkPDA;

namespace Belmost4PDA.Fasade
{
    public class StatesReader
    {
        public QuerySelect query;

        /// <summary>
        /// Initializes a new instance of the <see cref="StatesReader"/> class.
        /// </summary>
        public StatesReader()
        {
            query = new QuerySelect();
        }

        /// <summary>
        /// Loads states and return loaded data.
        /// </summary>
        /// <returns></returns>
        public List<StateData> Load()
        {
            List<StateData> states = null;
            if (query.Select(SQLStates.SelectAllStates))
            {
                List<DataRows.DataRows> rows = query.GetRows();
                states = new List<StateData>();
                foreach (DataRows.DataRows row in rows)
                {
                    states.Add(
                        new StateData(int.Parse(row.FieldByName("clsModes")), row.FieldByName("cls_Text"),
                                      int.Parse(row.FieldByNameDef("idPointer", "-1"))));
                }
            }
            return states;
        }
    }
}